package bs.app.android;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketConnection implements Connection {

	Socket soc = null;
	
	public SocketConnection(String IP, int port){
		try {
			soc = new Socket(IP, port);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public DataInputStream openDataInputStream() {
		try {
			return new DataInputStream(soc.getInputStream());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public InputStream openInputStream() {
		try {
			return soc.getInputStream();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public DataOutputStream openDataOutputStream() {
		try {
			return new DataOutputStream(soc.getOutputStream());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public OutputStream openOutputStream() {
		try {
			return soc.getOutputStream();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public void close() throws IOException {
		soc.close();
	}
}
